package com.gonsin.gview.common.po;

import com.gonsin.base.exceptions.MyException;
import com.gonsin.gview.common.auth.BaseResultCodes;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author fzy
 * @description: 小程序注册用户请求
 * @date 2023/6/26 14:32
 */
@Data
public class UserAddRequestMiniApp implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户真实姓名", required = true)
    private String realName;

    @ApiModelProperty(value = "手机号", required = true)
    private String phone;

    @ApiModelProperty(value = "所属单位", required = true)
    private String company;

    @ApiModelProperty(value = "所属部门", required = true)
    private String department;

    @ApiModelProperty(value = "岗位职务")
    private String job;

    @ApiModelProperty(value = "用户头像")
    private String avatar;

    @ApiModelProperty(value = "小程序miniOpenid", required = true)
    private String miniOpenid;

    @ApiModelProperty(value = "小程序unionId")
    private String unionId;

    public void checkParams() {

        if (StringUtils.isBlank(realName) || realName.length() > 64) {
            throw new MyException(BaseResultCodes.PARAM_ERROR, "用户真实姓名 参数不合法");
        }
        if (StringUtils.isBlank(phone) || phone.length() > 64) {
            throw new MyException(BaseResultCodes.PARAM_ERROR, "手机号 参数不合法");
        }
        if (StringUtils.isBlank(company) || company.length() > 64) {
            throw new MyException(BaseResultCodes.PARAM_ERROR, "所属部门 参数不合法");
        }
        if (StringUtils.isBlank(department) || department.length() > 64) {
            throw new MyException(BaseResultCodes.PARAM_ERROR, "所属部门 参数不合法");
        }
        if (StringUtils.isBlank(miniOpenid)) {
            throw new MyException(BaseResultCodes.PARAM_ERROR, "小程序miniOpenid 不能为空");
        }
        if (StringUtils.isBlank(unionId)) {
            throw new MyException(BaseResultCodes.PARAM_ERROR, "小程序unionId 不能为空");
        }
    }
}
